package com.cet.algorithm.数组;

import java.util.Arrays;

/**
 * @program: cet-practice
 * @description: 插入排序
 * @author: 陈恩涛
 * @create: 2023-05-05 08:20
 **/
public class InsertionSort {

    // 思想：打扑克抓牌的过程
    public static void main(String[] args) {
        int[] a = {1, 4, 2, 3, 5};
        int length = a.length;
        for (int i = 0; i < length; i++) {
            for (int j = i - 1; j >= 0; j--) {
                if (a[i] >= a[j]) {
                    break;
                } else {
                    int temp = a[j];
                    a[j] = a[i];
                    a[i] = temp;
                }
            }
        }
        Arrays.stream(a).forEach(System.out::println);
    }
}
